import java.util.Scanner;

public class DuLinkList {
   public DuLNode head;

    public DuLinkList(){
        head = new DuLNode();
        head.prior = head;
        head.next = head;
    }

    public DuLinkList(int i) throws Exception{
        this();
        Scanner sc = new Scanner(System.in);
        for(int j=0;j<i;j++)
            insert(0,sc.next());
    }

    private void insert(int i, Object x) throws Exception {
         DuLNode p = head.next;
         int j =0 ;
         while(!p.equals(head) && j<i){
             p = p.next;
             ++j;
         }
         /*if(j!=i && !p.equals(head)){
             throw new Exception("插入的位置不合法");
             *//*DuLNode s = new DuLNode(x);*//*
             p.prior.next = s ;
             s.prior = p.prior;
             s.next = p;
             p.prior = s;
         }*/
    }

    public void remove(int i)throws Exception{
        DuLNode p = head.next;
        int j = 0 ;
        while(!p.equals(head)  && j<i){
            p = p.next;
            ++j;
        }
        if(j!=i)
            throw new Exception("删除位置不合理");
            p.prior.next = p.next;
            p.next.prior = p.prior;

    }

    public void display(){
        DuLNode node = head.next;
        while(!node.equals(head)){
            System.out.print(node.date+"  ");
            node=node.next;
        }
        System.out.println();
    }

}
